extends Label

var instance_id: int
static var active_instances: Array = []
var base_font_size = 14  # 基础字体大小

func _ready() -> void:
	# 为每个实例创建独立的LabelSettings
	var new_label_settings = LabelSettings.new()
	new_label_settings.outline_size = 4
	new_label_settings.outline_color = Color(0, 0, 0, 1)
	new_label_settings.font_color = Color.WHITE
	# 设置固定字体大小，不受父节点scale影响
	new_label_settings.font_size = base_font_size
	label_settings = new_label_settings
	
	# 添加到活跃实例列表并分配ID
	active_instances.append(self)
	instance_id = active_instances.size() - 1
	
	var tween = create_tween().set_parallel(true).set_ease(Tween.EASE_OUT)
	tween.tween_property(self, "scale", Vector2.ONE, 0.2).from(Vector2.ZERO)
	# 减少向上移动距离
	tween.tween_property(self, "position:y", position.y - 20, 0.3)
	tween.tween_property(self, "scale", Vector2.ZERO, 0.5).set_delay(0.7)
	tween.tween_callback(self.queue_free).set_delay(1)

func _exit_tree():
	# 从活跃实例列表中移除
	active_instances.erase(self)

func set_number(number):
	text = "-" + str(number)

func set_color(color):
	# 只改变当前实例的颜色，不影响其他实例
	if label_settings:
		label_settings.font_color = color

func set_string(text_value):
	text = text_value

## 根据对象scale调整文字大小
func set_scale_factor(scale_factor: float):
	if label_settings:
		# 以1为基准，根据scale_factor调整字体大小
		label_settings.font_size = base_font_size * int(scale_factor)

## 重置实例计数器
static func reset_counter():
	active_instances.clear()
